<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>13章课后题2</title>
    <style>
        input,
        select,
        span {
            margin-right: 10px;
            font-size: 20px;
        }
    </style>
</head>

<body>
    <input type="text" id="first-id" placeholder="请输入数字" />
    <select id="oper">
        <option value="+">+</option>
        <option value="-">-</option>
        <option value="*">*</option>
        <option value="/">/</option>
    </select>
    <input type="text" id="second-id" placeholder="请输入数字" />
    <span>=</span>
    <input type="text" id="result-id" />
    <button id="btn-cal">计算</button>

    <script>
        document.getElementById('btn-cal').onclick = function () {
            let num1 = parseFloat(document.getElementById('first-id').value);
            let num2 = parseFloat(document.getElementById('second-id').value);

            let oper = document.getElementById('oper').value;

            document.getElementById('result-id').value = eval(num1 + oper + num2);
        }
    </script>
</body>

</html>